package com.ruoyi.common.core.redis;

import java.util.concurrent.TimeUnit;

import org.springframework.data.redis.core.RedisTemplate;

@SuppressWarnings(value = { "unchecked", "rawtypes" }) 
public class UpdateLockTimeoutTask implements Runnable{
    //uuid
    private String uuid;
 	private RedisTemplate redisTemplate;
    private String key;
	public UpdateLockTimeoutTask(String uuid, RedisTemplate redisTemplate, String key){
        this.uuid = uuid;
        this.redisTemplate = redisTemplate;
        this.key = key;
    }
 	@Override
    public void run(){
        //以uuid为key，当前线程id为value保存到Redis中
    	redisTemplate.opsForValue().set(uuid, String.valueOf(Thread.currentThread().getId()));
         //定义更新锁的过期时间
        while(true){
        	redisTemplate.expire(key, 30, TimeUnit.SECONDS);
            try{
                //每隔10秒执行一次
                Thread.sleep(10000);
            }catch (InterruptedException e){
                e.printStackTrace();
            }
        }
    }
}
